package com.ruoyi.ruoyiqywechat.controller;

import java.util.List;
import java.io.IOException;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.qy.request.PreOrderRequest;
import com.ruoyi.common.qy.response.PreOrderResponse;
import org.apache.http.client.methods.HttpGet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.ruoyiqywechat.domain.OrderQy;
import com.ruoyi.ruoyiqywechat.service.IOrderQyService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 订单Controller
 *
 * @author 好六
 * @date 2025-10-10
 */
@RestController
@RequestMapping("/orderQy")
public class OrderQyController extends BaseController
{
    @Autowired
    private IOrderQyService orderQyService;
    /**
     * 预下单
     */
    //(value = "预下单")
    @RequestMapping(value = "/pre/order", method = RequestMethod.POST)
    public R<Map<String, Object>> preOrder(@RequestBody @Validated PreOrderRequest request) {
        return R.ok(orderQyService.preOrder(request).getColumns());
    }
    /**
     * 加载预下单
     */
    ///(value = "加载预下单")
    @RequestMapping(value = "load/pre/{preOrderNo}", method = RequestMethod.GET)
    public R<PreOrderResponse> loadPreOrder(@PathVariable String preOrderNo) {
        return R.ok(orderQyService.loadPreOrder(preOrderNo));
    }
    /**
     * 创建订单
     */
    //(value = "创建订单")
    @RequestMapping(value = "/create", method = RequestMethod.GET)
    public R<Map<String, Object>> createOrder(@RequestParam("preOrderNo") String preOrderNo) {
        return R.ok(orderQyService.createOrder(preOrderNo).getColumns());
    }
    /**
     * 查询订单列表
     */
  //("ruoyiqywechat:orderQy:list")
    @GetMapping("/list")
    public TableDataInfo list(OrderQy orderQy)
    {
        startPage();
        List<OrderQy> list = orderQyService.selectOrderQyList(orderQy);
        return getDataTable(list);
    }

    /**
     * 导出订单列表
     */
  //("ruoyiqywechat:orderQy:export")
    @Log(title = "订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OrderQy orderQy)
    {
        List<OrderQy> list = orderQyService.selectOrderQyList(orderQy);
        ExcelUtil<OrderQy> util = new ExcelUtil<OrderQy>(OrderQy.class);
        util.exportExcel(response, list, "订单数据");
    }

    /**
     * 获取订单详细信息
     */
  //("ruoyiqywechat:orderQy:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(orderQyService.selectOrderQyById(id));
    }

    /**
     * 新增订单
     */
  //("ruoyiqywechat:orderQy:add")
    @Log(title = "订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OrderQy orderQy)
    {
        return toAjax(orderQyService.insertOrderQy(orderQy));
    }

    /**
     * 修改订单
     */
  //("ruoyiqywechat:orderQy:edit")
    @Log(title = "订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OrderQy orderQy)
    {
        return toAjax(orderQyService.updateOrderQy(orderQy));
    }

    /**
     * 删除订单
     */
  //("ruoyiqywechat:orderQy:remove")
    @Log(title = "订单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(orderQyService.deleteOrderQyByIds(ids));
    }
}
